package com.tc.security.core.authentication;

import com.tc.security.core.properties.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * @Auther: tianchao
 * @Date: 2020/6/26 01:19
 * @Description: 表单登录配置
 */
@Component
public class FormAuthenticationConfig {

    @Autowired
    @Qualifier(value = "tcAuthenticationSuccessHandler")
    private AuthenticationSuccessHandler tcAuthenticationSuccessHandler;

    @Autowired
    @Qualifier(value = "tcAuthenticationFailureHandler")
    protected AuthenticationFailureHandler tcAuthenticationFailureHandler;

    public void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
                .loginProcessingUrl(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_FORM)
                .successHandler(tcAuthenticationSuccessHandler)
                .failureHandler(tcAuthenticationFailureHandler);
    }
}
